package com.g001.model.powers;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import com.g001.enums.BlockType;
import com.g001.enums.MessagePositionType;
import com.g001.model.GCharacter;
import com.g001.model.Player;

public class CursedAction extends Action {	

	private MessageAction message;
	private GCharacter character;
	private GCharacter opponent;

	private int damage;
	
	public CursedAction(final GCharacter character,GCharacter opponent, int damage){
		this.character = character;
		this.opponent = opponent;
		this.damage = damage;		
		type = BlockType.ATTACK;
	}
	
	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		message.render(container, game, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		message.update(container, game, delta);
	}

	@Override
	public void action() {
		message = new MessageAction("-"+damage+" of magic", (character instanceof Player? MessagePositionType.LEFT:MessagePositionType.RIGHT));
		character.setCurrentAnimation(character.getCharacterType().getHurtAnim());
		message.action();
		if(character.getMagic().getValue()-damage>0) {
			character.getMagic().remove(damage);
		} else {
			character.getMagic().setValue(0);
		}
		
	}
	
	@Override
	public void setBonus(final int bonus){
		this.bonus = bonus;
		damage *= bonus;
	}

	@Override
	public boolean isFinished() {
		return message.isFinished();
	}

}
